KeyedCollection
Represents an abstract dictionary-backed collection that manages key-value pairs with customizable behavior.
Implementa: IDictionary<T, T>, ICollection<KeyValuePair<T, T>>, IEnumerable<KeyValuePair<T, T>>, IEnumerable
Constructores
protected KeyedCollection(IDictionary<TKey, TValue> innerDictionary)
keyedCollection = KeyedCollection(innerDictionary)
Represents an abstract dictionary-backed collection that manages key-value pairs with customizable behavior.
protected KeyedCollection(IEqualityComparer<TKey> comparer)
keyedCollection = KeyedCollection(comparer)
Initializes a new instance of the KeyedCollection class with a specified key comparer.
- comparer
- The equality comparer for keys, or null to use the default comparer.
protected KeyedCollection()
keyedCollection = KeyedCollection()
Initializes a new instance of the KeyedCollection class with a default dictionary.
Propiedades
public virtual int Count { get; }
value = keyedCollection.Count
Gets the number of key-value pairs in the collection.
protected IDictionary<TKey, TValue> InnerDictionary { get; }
value = keyedCollection.InnerDictionary
Gets the underlying dictionary that stores the key-value pairs.
public virtual TValue Item { get; set; }
value = keyedCollection.Item
keyedCollection.Item = value
Gets or sets the value associated with the specified key.
- key
- The key whose value is to be retrieved or set.
Devuelve: The value associated with the specified key.
public ICollection<TKey> Keys { get; }
value = keyedCollection.Keys
Gets a collection containing the keys in the dictionary.
System#Collections#Generic#ICollection{System#Collections#Generic#KeyValuePair{TKey,TValue}}#IsReadOnly
Gets a value indicating whether the collection is read-only.
public ICollection<TValue> Values { get; }
value = keyedCollection.Values
Gets a collection containing the values in the dictionary.
Métodos
public void Add(KeyValuePair<TKey, TValue> item)
keyedCollection.Add(item)
Adds a key-value pair to the collection.
- item
- The key-value pair to add.
public virtual void Add(TKey key, TValue value)
keyedCollection.Add(key, value)
Adds the specified key-value pair to the collection.
- key
- The key to add.
- value
- The value to add.
protected virtual bool CanAdd(TKey key, TValue value)
result = keyedCollection.CanAdd(key, value)
Determines whether a key-value pair can be added to the collection.
- key
- The key to check.
- value
- The value to check.
Devuelve: True if the pair can be added; otherwise, false.
public bool Contains(KeyValuePair<TKey, TValue> item)
result = keyedCollection.Contains(item)
Determines whether the collection contains a specific key-value pair.
- item
- The key-value pair to locate.
Devuelve: True if the pair is found; otherwise, false.
public bool ContainsKey(TKey key)
result = keyedCollection.ContainsKey(key)
Determines whether the collection contains an element with the specified key.
- key
- The key to locate.
Devuelve: True if the key is found; otherwise, false.
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
keyedCollection.CopyTo(array, arrayIndex)
Copies the elements of the collection to an array, starting at the specified index.
- array
- The destination array to copy to.
- arrayIndex
- The zero-based index in the array at which copying begins.
public virtual IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
result = keyedCollection.GetEnumerator()
Returns an enumerator that iterates through the collection.
Devuelve: An IEnumerator that can be used to iterate through the collection.
protected virtual void OnAdded(TKey key, TValue value)
keyedCollection.OnAdded(key, value)
Called after a key-value pair has been added to the collection.
- key
- The key that was added.
- value
- The value that was added.
protected virtual void OnAdding(TKey key, TValue value)
keyedCollection.OnAdding(key, value)
Called before adding a key-value pair to the collection.
- key
- The key being added.
- value
- The value being added.
protected virtual void OnCleared()
keyedCollection.OnCleared()
Called after all items have been cleared from the collection.
protected virtual void OnClearing()
keyedCollection.OnClearing()
Called before clearing all items from the collection.
protected virtual void OnRemoved(TKey key, TValue value)
keyedCollection.OnRemoved(key, value)
Called after a key-value pair has been removed from the collection.
- key
- The key that was removed.
- value
- The value that was removed.
protected virtual void OnRemoving(TKey key, TValue value)
keyedCollection.OnRemoving(key, value)
Called before removing a key-value pair from the collection.
- key
- The key being removed.
- value
- The value being removed.
protected virtual void OnSetted(TKey key, TValue value)
keyedCollection.OnSetted(key, value)
Called after a new value has been set for an existing key.
- key
- The key that was updated.
- value
- The new value that was set.
protected virtual void OnSetting(TKey key, TValue value)
keyedCollection.OnSetting(key, value)
Called before setting a new value for an existing key.
- key
- The key being updated.
- value
- The new value to set.
public bool Remove(KeyValuePair<TKey, TValue> item)
result = keyedCollection.Remove(item)
Removes a specific key-value pair from the collection.
- item
- The key-value pair to remove.
Devuelve: True if the pair was found and removed; otherwise, false.
public virtual bool Remove(TKey key)
result = keyedCollection.Remove(key)
Removes the value with the specified key from the collection.
- key
- The key of the element to remove.
Devuelve: True if the element was found and removed; otherwise, false.
System#Collections#IEnumerable#GetEnumerator()
Returns an enumerator that iterates through the collection (non-generic version).
Devuelve: An IEnumerator that can be used to iterate through the collection.
public virtual bool TryGetValue(TKey key, TValue value)
result = keyedCollection.TryGetValue(key, value)
Attempts to retrieve the value associated with the specified key.
- key
- The key to locate.
- value
- When this method returns, contains the value associated with the key if found; otherwise, the default value of .
Devuelve: True if the key was found; otherwise, false.